<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>入院登记</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">

</head>
<style>
    .layui-input-block {
        width: 260px;
        height: 20px;
    }

    .layui-btn {
        margin-left: 600px;
        margin-top: 40px;
    }

    #layui-btn {
        margin-left: 730px;
        margin-top: -55px;
    }
</style>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item"><h1>入院登记</h1></div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">姓名:</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required"
                       lay-reqtext="必填项不能为空" placeholder="请输入" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">身份证号:</label>
            <div class="layui-input-block">
                <input type="text" name="idNumber" lay-verify="required"
                       lay-reqtext="必填项不能为空" placeholder="请输入" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">出生日期:</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="test1" placeholder="yyyy-MM-dd">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">家庭住址:</label>
            <div class="layui-input-block">
                <input type="text" name="home" lay-verify="required"
                       lay-reqtext="必填项不能为空" placeholder="请输入" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">工作单位:</label>
            <div class="layui-input-block">
                <input type="text" name="home" lay-verify="required"
                       lay-reqtext="必填项不能为空" placeholder="请输入" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <!-- <div class="layui-inline">
             <label class="layui-form-label">科室号:</label>  &lt;!&ndash;联动选择框&ndash;&gt;
             <div class="layui-input-block">
                 <input type="text" name="home" lay-verify="required"
                        lay-reqtext="必填项不能为空" placeholder="请输入" autocomplete="off"
                        class="layui-input">
             </div>
         </div>
         <div class="layui-inline">
             <label class="layui-form-label">主治医师:</label>  &lt;!&ndash;联动选择框&ndash;&gt;
             <div class="layui-input-block">
                 <input type="text" name="home" lay-verify="required"
                        lay-reqtext="必填项不能为空" placeholder="请输入" autocomplete="off"
                        class="layui-input">
             </div>
         </div>-->
        <!--   科室号和主治医师 联动下拉框-->
        <div class="layui-inline" style="margin-bottom: 15px;">
            <label class="layui-form-label">科室号:</label>
            <div class="layui-input-inline" style="width:260px">
                <select name="departName" id="departName" lay-filter="departNameFilter" lay-search="">
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div class="layui-inline" style="margin-bottom: 15px;">
            <label class="layui-form-label" style="color: black">主治医师:</label>
            <div class="layui-input-inline" style="width:260px">
                <select name="doctorId" id="doctorId" lay-filter="doctorIdFilter" lay-search="">
                    <option value=""></option>
                </select>
            </div>
        </div>
        <!--   病房类型和病房号  联动下拉框-->
        <div class="layui-inline" style="margin-bottom: 15px;">
            <label class="layui-form-label">病房类型:</label>
            <div class="layui-input-inline" style="width:260px">
                <select name="typeName" id="typeName" lay-filter="typeNameFilter" lay-search="">
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div class="layui-inline" style="margin-bottom: 15px;">
            <label class="layui-form-label" style="color: black">病房号:</label>
            <div class="layui-input-inline" style="width:260px">
                <select name="roomId" id="roomId" lay-filter="doctorIdFilter" lay-search="">
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">床位号:</label>
            <div class="layui-input-block">
                <input type="text" name="bedId" lay-verify="required"
                       lay-reqtext="必填项不能为空" placeholder="请输入" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">紧急联系人:</label>
            <div class="layui-input-block">
                <input type="text" name="parent" lay-verify="required"
                       lay-reqtext="必填项不能为空" placeholder="请输入" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">联系人电话:</label>
            <div class="layui-input-block">
                <input type="text" name="parentPhone" lay-verify="required"
                       lay-reqtext="必填项不能为空" placeholder="请输入" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">病人电话:</label>
            <div class="layui-input-block">
                <input type="text" name="phone" lay-verify="required"
                       lay-reqtext="必填项不能为空" placeholder="请输入" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">入院时间:</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="test" placeholder="yyyy-MM-dd" name="enterTime">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">入院状态</label>
            <div class="layui-input-inline" style="width:260px">
                <select name="statusId" lay-verify="required" lay-search="">
                    <option value="1">一般</option>
                    <option value="2">紧急</option>
                    <option value="3">严重</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary" id="layui-btn">重置</button>
        </div>
    </div>
    </div>
</form>
<script src="../layui/layui.js" charset="utf-8"></script>
<script src="../js/jquery.form.min.js" type="text/javascript"></script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer//弹框
            , layedit = layui.layedit
            , laydate = layui.laydate;  //日期组件

        //常规用法 渲染那个时间框的！！！
        laydate.render({
            elem: '#test'
        });
        laydate.render({
            elem: '#test1'
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            });
            return false;
        });
    });


    // 得到科室号
    function getDepart() {
        $.ajax({
            url: this.api + "/WyStoriedBuilding/list",  //需要修改
            dataType: 'json',
            type: 'post',
            success: function (data) {
                $.each(data, function (index, item) {
                    $('#departName').append(new Option(item.name, item.id));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        });
    };

    // 得到主治医师
    function getDoctor(data) {
        var params = {
            departName: data.value
        };
        //检查项目添加到下拉框中
        $.ajax({
            url: this.api + "/WyHousingInformation/getHousing", //需要修改
            dataType: 'json',
            data: JSON.stringify(params),
            contentType: "application/json",    //需要修改???
            type: 'post',
            success: function (data) {
                $("#doctorId").empty();//清空下拉框的值
                $.each(data, function (index, item) {
                    $('#doctorId').append(new Option(item.name, item.id));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        });
    };

    //得到病房类型
    function getRoomType() {
        $.ajax({
            url: this.api + "/WyStoriedBuilding/list",  //需要修改
            dataType: 'json',
            type: 'post',
            success: function (data) {
                $.each(data, function (index, item) {
                    $('#TypeName').append(new Option(item.name, item.id));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        });
    };

    //得到病房号
    function getRoom(data) {
        var params = {
            typeName: data.value
        };
        //检查项目添加到下拉框中
        $.ajax({
            url: this.api + "/WyHousingInformation/getHousing", //需要修改
            dataType: 'json',
            data: JSON.stringify(params),
            contentType: "application/json",    //需要修改???
            type: 'post',
            success: function (data) {
                $("#roomId").empty();//清空下拉框的值
                $.each(data, function (index, item) {
                    $('#roomId').append(new Option(item.name, item.id));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        });
    };

    // 联动
    layui.use('form', function () {
        form.on('select(departNameFilter)', function (data) {
            this.getHousing(data);   //需要修改
        });
        form.on('select(typeNameFilter)', function (data) {
            this.getHousing(data);   //需要修改
        });
    });
</script>
</body>
</html>